#include "language.h"

using namespace CppStory;

static Language* g_language = NULL;

Language* Language::instance()
{
    if (g_language == NULL)
        g_language = new Language();
    return g_language;
}

Language::Language()
: language("en")
{
}

void Language::register_items(const char* lang, LanguageStrItem* items)
{
    language_items[lang] = items;
}

void Language::set_language(const char* lang)
{
    language = lang;
}

LanguageStrItem* Language::get_items(const char* language)
{
    std::map <std::string, LanguageStrItem*>::iterator iter;
    iter = language_items.find(language);
    if(iter == language_items.end())
        return NULL;
    return language_items[language];
}

const char* Language::get_feature_str()
{
    LanguageStrItem* items = get_items(language.c_str());
    if (NULL == items)
        return NULL;
    return items[LST_FEATURE].str.c_str();
}

const char* Language::get_in_order_str()
{
    LanguageStrItem* items = get_items(language.c_str());
    if (NULL == items)
        return NULL;
    return items[LST_IN_ORDER].str.c_str();
}

const char* Language::get_as_str()
{
    LanguageStrItem* items = get_items(language.c_str());
    if (NULL == items)
        return NULL;
    return items[LST_AS].str.c_str();
}

const char* Language::get_i_want_str()
{
    LanguageStrItem* items = get_items(language.c_str());
    if (NULL == items)
        return NULL;
    return items[LST_I_WANT].str.c_str();
}

const char* Language::get_scenario_str()
{
    LanguageStrItem* items = get_items(language.c_str());
    if (NULL == items)
        return NULL;
    return items[LST_SCENARIO].str.c_str();
}

const char* Language::get_background_str()
{
    LanguageStrItem* items = get_items(language.c_str());
    if (NULL == items)
        return NULL;
    return items[LST_BACKGROUND].str.c_str();
}

const char* Language::get_given_str()
{
    LanguageStrItem* items = get_items(language.c_str());
    if (NULL == items)
        return NULL;
    return items[LST_GIVEN].str.c_str();
}

const char* Language::get_and_str()
{
    LanguageStrItem* items = get_items(language.c_str());
    if (NULL == items)
        return NULL;
    return items[LST_AND].str.c_str();
}

const char* Language::get_when_str()
{
    LanguageStrItem* items = get_items(language.c_str());
    if (NULL == items)
        return NULL;
    return items[LST_WHEN].str.c_str();
}

const char* Language::get_then_str()
{
    LanguageStrItem* items = get_items(language.c_str());
    if (NULL == items)
        return NULL;
    return items[LST_THEN].str.c_str();
}

const char* Language::get_but_str()
{
    LanguageStrItem* items = get_items(language.c_str());
    if (NULL == items)
        return NULL;
    return items[LST_BUT].str.c_str();
}

